<template>
  <div class="dashboard-editor-container">
    <!-- 平台管理员登录统计显示 -->
    <el-row v-if="identity == 'admin'" :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('user/user')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">用户数量</div>
              <count-to
                :start-val="0"
                :end-val="admin.userTotal"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('views/herb')">
            <div class="card-panel-icon-wrapper icon-message">
              <svg-icon icon-class="message" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">车源数量</div>
              <count-to
                :start-val="0"
                :end-val="admin.herbTotal"
                :duration="3000"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('audit/userAudit')">
            <div class="card-panel-icon-wrapper icon-money">
              <svg-icon icon-class="skill" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">注册待审核数量</div>
              <count-to
                :start-val="0"
                :end-val="admin.userAuditTotal"
                :duration="3200"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('audit/purchaseAudit')">
            <div class="card-panel-icon-wrapper icon-shoppingCard">
              <svg-icon icon-class="skill" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">采购待审核数量</div>
              <count-to
                :start-val="0"
                :end-val="admin.purchaseAuditTotal"
                :duration="3600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
    </el-row>
    <!-- 饮片厂登录统计显示 -->
    <el-row v-if="identity == 'manufactor'" :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchase')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">待发布</div>
              <count-to
                :start-val="0"
                :end-val="manufactor.waitReleased"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchase')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">审核中</div>
              <count-to
                :start-val="0"
                :end-val="manufactor.underReview"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchaseManage')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">已审核</div>
              <count-to
                :start-val="0"
                :end-val="manufactor.reviewed"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchaseManage')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">已完结</div>
              <count-to
                :start-val="0"
                :end-val="manufactor.closed"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
    </el-row>
    <!-- 经销商登录统计显示 -->
    <el-row v-if="identity == 'distributor'" :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchase')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">待发布</div>
              <count-to
                :start-val="0"
                :end-val="distributor.waitReleased"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchase')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">审核中</div>
              <count-to
                :start-val="0"
                :end-val="distributor.underReview"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchaseManage')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">已审核</div>
              <count-to
                :start-val="0"
                :end-val="distributor.reviewed"
                :duration="2600"
                class="card-panel-num"
              />
            </div></div></el-card>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <el-card class="box-card" body-style="padding:0px;">
          <div class="card-panel" @click="handleSetLineChartData('mall/purchaseManage')">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">已完结</div>
              <count-to
                :start-val="0"
                :end-val="distributor.closed"
                :duration="2600"
                class="card-panel-num"
              />
            </div>
          </div> </el-card></el-col>
    </el-row>

    <el-card
      class="flow-card"
      body-style="display: flex;flex-direction: column;justify-content:center;"
    >
      <img class="flow-img" :src="background" width="100%" height="100%">
    </el-card>
  </div>
</template>

<script>
import { info } from '@/api/dashboard'
import CountTo from 'vue-count-to'

export default {
  components: {
    CountTo
  },
  data() {
    return {
      identity: '',
      background:process.env.VUE_APP_IMAGES_API+'/index_background.jpg',
      admin: {
        userTotal: 0,
        herbTotal: 0,
        userAuditTotal: 0,
        purchaseAuditTotal: 0
      },
      manufactor: {
        waitReleased: 0,
        underReview: 0,
        reviewed: 0,
        closed: 0
      },
      distributor: {
        waitReleased: 0,
        underReview: 0,
        reviewed: 0,
        closed: 0
      }
    }
  },
  created() {
    info().then((response) => {
      this.identity = response.data.data.identity
      this.admin = response.data.data.admin || this.admin
      this.manufactor = response.data.data.manufactor || this.manufactor
      this.distributor = response.data.data.distributor || this.distributor
    })
  },
  methods: {
    handleSetLineChartData(type) {
      // this.$emit('handleSetLineChartData', type)
      this.$router.push({ path: type})
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }
  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);
    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }
      .icon-people {
        background: #40c9c6;
      }
      .icon-message {
        background: #36a3f7;
      }
      .icon-money {
        background: #f4516c;
      }
      .icon-shoppingCard {
        background: #34bfa3;
      }
    }
    .icon-people {
      color: #40c9c6;
    }
    .icon-message {
      color: #36a3f7;
    }
    .icon-money {
      color: #f4516c;
    }
    .icon-shoppingCard {
      color: #34bfa3;
    }
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-icon {
      float: left;
      font-size: 48px;
    }
    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;
      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }
      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
</style>
